package com.dlc.apk.ui.view

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ItemDecoration


class MyGridSpacingItemDecoration(private val spanCount: Int, private val leftSpace: Int/*, private val bottomSpace: Int*/) : ItemDecoration() {
    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
        val pos = parent.getChildAdapterPosition(view)
        val columnIndex = pos % spanCount
        val rowIndex = pos / spanCount
        //每行的开始列左边距设为0
        val leftMargin = if (columnIndex != 0) leftSpace else 0
        val bottomMargin = leftSpace
        //LogPlus.e("getItemOffsets", "pos:$pos, mod:$columnIndex, leftMargin:$leftMargin")
        outRect.left = leftMargin
        outRect.bottom = bottomMargin
    }
}